define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    edit_url: 'order/edit',
                    del_url: 'order/del',
                    multi_url: 'order/multi',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'ware_id', title: __('Ware_id')},
                        {field: 'product_id', title: __('Product_id'),visible: false},
                        {field: 'clause_id', title: __('Clause_id'),visible: false},
                        {field: 'ware_name', title: __('Ware_name')},
                        {field: 'order_no', title: __('Order_no'),visible: false},
                        {field: 'refundTime', title: __('Refundtime'),visible: false},
                        {field: 'visitTime', title: __('Visittime'),visible: false},
                        {field: 'returnVisitStatus', title: __('Returnvisitstatus'), formatter: Table.api.formatter.status,visible: false},
                        {field: 'guaranteeType', title: __('Guaranteetype'),visible: false},
                        {field: 'guaranteeTerm', title: __('Guaranteeterm'),visible: false},
                        {field: 'orderStatus', title: __('Orderstatus'), formatter: Table.api.formatter.status},
                        {field: 'mechanId', title: __('Mechanid')},
                        {field: 'orderId', title: __('Orderid')},
                        {field: 'policy_no', title: __('Policy_no')},
                        {field: 'commission_owner', title: __('Commission_owner'),visible: false},
                        {field: 'seller', title: __('Seller'),visible: false},
                        {field: 'product_name', title: __('Product_name'),visible: false},
                        {field: 'clause_name', title: __('Clause_name'),visible: false},
                        {field: 'commission', title: __('Commission'), operate:'BETWEEN'},
                        {field: 'payment', title: __('Payment'),visible: false},
                        {field: 'payPerm', title: __('Payperm'),visible: false},
                        {field: 'expireTime', title: __('Expiretime'),visible: false},
                        {field: 'totalInsured', title: __('Totalinsured'), operate:'BETWEEN',visible: false},
                        {field: 'totalPremium', title: __('Totalpremium'), operate:'BETWEEN',visible: false},
                        {field: 'premium', title: __('Premium'), operate:'BETWEEN'},
                        {field: 'fundAccount_type', title: __('Fundaccount_type'), searchList: {"1":__('Fundaccount_type 1'),"2":__('Fundaccount_type 2')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'commission_type', title: __('Commission_type'),visible: false},
                        {field: 'settle_status', title: __('Settle_status'), formatter: Table.api.formatter.status,visible: false},
                        {field: 'remake', title: __('Remake'),visible: false},
                        {field: 'pay', title: __('Pay'),visible: false},
                        {field: 'expires', title: __('Expires'),visible: false},
                        {field: 'pay_freq', title: __('Pay_freq'),visible: false},
                        {field: 'insure_data', title: __('Insure_data')},
                        {field: 'creat_date_end', title: __('Creat_date_end'),visible: false},
                        {field: 'effective_date', title: __('Effective_date'),visible: false},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                        {field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});